﻿//Copyright 2011 - Jonathan Allen

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Granite.ComponentModel;

namespace Granite.Collections
{

	///// <summary>
	///// A dictionary that notifies observers when values change
	///// </summary>
	///// <typeparam name="TKey"></typeparam>
	///// <typeparam name="TValue"></typeparam>
	///// <remarks>This class is not suitable for XAML-based data binding because it is not ordered.</remarks>
 //   public class ObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, INotifyDictionaryChanged
	//{
	//	private readonly IDictionary<TKey, TValue> m_Core = new Dictionary<TKey, TValue>();

	//	/// <summary>
	//	/// Indicates the dictionary changed.
	//	/// </summary>
 //       public event EventHandler<DictionaryChangedEventArgs> DictionaryChanged;

 //       private void OnDictionaryChanged(DictionaryChangedEventArgs e)
	//	{
	//		if (DictionaryChanged != null)
	//			DictionaryChanged(this, e);

	//		OnPropertyChanged(CommonProperties.ItemIndexedProperty);
	//	}


 //       /// <summary>
 //       /// Raises the <see cref="E:System.Collections.ObjectModel.ObservableCollection`1.PropertyChanged" /> event with the provided arguments.
 //       /// </summary>
 //       /// <param name="propertyName">
 //       /// Property that is being changed.
 //       /// </param>
 //       protected void OnPropertyChanged(string propertyName)
 //       {
 //           OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
 //       }

	//	/// <summary>
	//	/// Indicates a property on the dictionary changed.
	//	/// </summary>
	//	/// <param name="e"></param>
	//	protected void OnPropertyChanged(PropertyChangedEventArgs e)
	//	{
	//		if (PropertyChanged != null)
	//			PropertyChanged(this, e);
	//	}

	//	/// <summary>
	//	/// Adds an element with the provided key and value to the <see cref="T:System.Collections.Generic.IDictionary`2" />.
	//	/// </summary>
	//	/// <param name="key">
	//	/// The object to use as the key of the element to add.
	//	/// </param>
	//	/// <param name="value">
	//	/// The object to use as the value of the element to add.
	//	/// </param>
	//	/// <exception cref="T:System.ArgumentNullException">
	//	/// <paramref name="key" /> is null.
	//	/// </exception>
	//	/// <exception cref="T:System.ArgumentException">
	//	/// An element with the same key already exists in the <see cref="T:System.Collections.Generic.IDictionary`2" />.
	//	/// </exception>
	//	/// <exception cref="T:System.NotSupportedException">
	//	/// The <see cref="T:System.Collections.Generic.IDictionary`2" /> is read-only.
	//	/// </exception>
	//	public void Add(TKey key, TValue value)
	//	{
	//		InsertItem(key, value);
	//	}

	//	/// <summary>
	//	/// Determines whether the <see cref="T:System.Collections.Generic.IDictionary`2" /> contains an element with the specified key.
	//	/// </summary>
	//	/// <returns>
	//	/// true if the <see cref="T:System.Collections.Generic.IDictionary`2" /> contains an element with the key; otherwise, false.
	//	/// </returns>
	//	/// <param name="key">
	//	/// The key to locate in the <see cref="T:System.Collections.Generic.IDictionary`2" />.
	//	/// </param>
	//	/// <exception cref="T:System.ArgumentNullException">
	//	/// <paramref name="key" /> is null.
	//	/// </exception>
	//	public bool ContainsKey(TKey key)
	//	{
	//		return m_Core.ContainsKey(key);
	//	}

	//	/// <summary>
	//	/// Gets an <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the <see cref="T:System.Collections.Generic.IDictionary`2" />.
	//	/// </summary>
	//	/// <returns>
	//	/// An <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the object that implements <see cref="T:System.Collections.Generic.IDictionary`2" />.
	//	/// </returns>
	//	public ICollection<TKey> Keys
	//	{
	//		get { return m_Core.Keys; }
	//	}

	//	/// <summary>
	//	/// Removes the element with the specified key from the <see cref="T:System.Collections.Generic.IDictionary`2" />.
	//	/// </summary>
	//	/// <returns>
	//	/// true if the element is successfully removed; otherwise, false.  This method also returns false if <paramref name="key" /> was not found in the original <see cref="T:System.Collections.Generic.IDictionary`2" />.
	//	/// </returns>
	//	/// <param name="key">
	//	/// The key of the element to remove.
	//	/// </param>
	//	/// <exception cref="T:System.ArgumentNullException">
	//	/// <paramref name="key" /> is null.
	//	/// </exception>
	//	/// <exception cref="T:System.NotSupportedException">
	//	/// The <see cref="T:System.Collections.Generic.IDictionary`2" /> is read-only.
	//	/// </exception>
	//	public bool Remove(TKey key)
	//	{
	//		if (!m_Core.ContainsKey(key))
	//			return false;

	//		RemoveItem(key, m_Core[key]);
	//		return true;
	//	}

	//	/// <summary>
	//	/// 
	//	/// </summary>
	//	/// <param name="key"></param>
	//	/// <param name="value"></param>
	//	/// <returns></returns>
	//	public bool TryGetValue(TKey key, out TValue value)
	//	{
	//		return m_Core.TryGetValue(key, out value);
	//	}

	//	/// <summary>
	//	/// Gets an <see cref="T:System.Collections.Generic.ICollection`1" /> containing the values in the <see cref="T:System.Collections.Generic.IDictionary`2" />.
	//	/// </summary>
	//	/// <returns>
	//	/// An <see cref="T:System.Collections.Generic.ICollection`1" /> containing the values in the object that implements <see cref="T:System.Collections.Generic.IDictionary`2" />.
	//	/// </returns>
	//	public ICollection<TValue> Values
	//	{
	//		get { return m_Core.Values; }
	//	}

	//	/// <summary>
	//	/// 
	//	/// </summary>
	//	public TValue this[TKey key]
	//	{
	//		get { return m_Core[key]; }
	//		set
	//		{
	//			if (m_Core.ContainsKey(key))
	//				SetItem(key, m_Core[key], value);
	//			else
	//				InsertItem(key, value);
	//		}
	//	}

	//	/// <summary>
	//	/// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1" />.
	//	/// </summary>
	//	/// <param name="item">
	//	/// The object to add to the <see cref="T:System.Collections.Generic.ICollection`1" />.
	//	/// </param>
	//	/// <exception cref="T:System.NotSupportedException">
	//	/// The <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only.
	//	/// </exception>
	//	public void Add(KeyValuePair<TKey, TValue> item)
	//	{
	//		InsertItem(item.Key, item.Value);
	//	}

	//	/// <summary>
	//	/// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1" />.
	//	/// </summary>
	//	/// <exception cref="T:System.NotSupportedException">
	//	/// The <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only. 
	//	/// </exception>
	//	public void Clear()
	//	{
	//		ClearItems();
	//	}

	//	/// <summary>
	//	/// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1" /> contains a specific value.
	//	/// </summary>
	//	/// <returns>
	//	/// true if <paramref name="item" /> is found in the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false.
	//	/// </returns>
	//	/// <param name="item">
	//	/// The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1" />.
	//	/// </param>
	//	public bool Contains(KeyValuePair<TKey, TValue> item)
	//	{
	//		return m_Core.Contains(item);
	//	}

	//	/// <summary>
	//	/// 
	//	/// </summary>
	//	/// <param name="array"></param>
	//	/// <param name="arrayIndex"></param>
	//	public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
	//	{
 //           m_Core.CopyTo(array, arrayIndex);
	//	}


	//	/// <summary>
	//	/// Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1" />.
	//	/// </summary>
	//	/// <returns>
	//	/// The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1" />.
	//	/// </returns>
	//	public int Count
	//	{
	//		get { return m_Core.Count; }
	//	}

	//	/// <summary>
	//	/// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1" />.
	//	/// </summary>
	//	/// <returns>
	//	/// true if <paramref name="item" /> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false. This method also returns false if <paramref name="item" /> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1" />.
	//	/// </returns>
	//	/// <param name="item">
	//	/// The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1" />.
	//	/// </param>
	//	/// <exception cref="T:System.NotSupportedException">
	//	/// The <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only.
	//	/// </exception>
	//	public bool Remove(KeyValuePair<TKey, TValue> item)
	//	{
	//		if (!m_Core.Contains(item))
	//			return false;
	//		RemoveItem(item.Key, item.Value);
	//		return true;
	//	}

	//	/// <summary>
	//	/// Returns an enumerator that iterates through the collection.
	//	/// </summary>
	//	/// <returns>
	//	/// A <see cref="T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the collection.
	//	/// </returns>
	//	/// <filterpriority>1</filterpriority>
	//	public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
	//	{
	//		return m_Core.GetEnumerator();
	//	}

	//	/// <summary>
	//	/// Returns an enumerator that iterates through the collection.
	//	/// </summary>
	//	/// <returns>
	//	/// A <see cref="T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the collection.
	//	/// </returns>
	//	/// <filterpriority>1</filterpriority>
	//	System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
	//	{
	//		return m_Core.GetEnumerator();
	//	}


	//	/// <summary>
	//	/// Occurs when a property value changes.
	//	/// </summary>
	//	public event PropertyChangedEventHandler PropertyChanged;

	//	bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly
	//	{
	//		get { return false; }
	//	}


	//	/// <summary>
	//	/// This is called whenever an item is added to the dictionary
	//	/// </summary>
	//	/// <param name="key"></param>
	//	/// <param name="value"></param>
	//	protected virtual void InsertItem(TKey key, TValue value)
	//	{
	//		m_Core.Add(key, value);
 //           OnDictionaryChanged(new DictionaryChangedEventArgs(NotifyDictionaryChangedAction.Add, key, value));
    //		OnPropertyChanged(CommonProperties.CountProperty);
	//	}

	//	/// <summary>
	//	/// This is called whenever an item is removed from the dictionary
	//	/// </summary>
	//	/// <param name="key"></param>
	//	/// <param name="value"></param>
	//	protected virtual void RemoveItem(TKey key, TValue value)
	//	{
	//		m_Core.Remove(key);
 //           OnDictionaryChanged(new DictionaryChangedEventArgs(NotifyDictionaryChangedAction.Remove, key, value));
    //		OnPropertyChanged(CommonProperties.CountProperty);
	//	}

	//	/// <summary>
	//	/// This is called when Clear is invoked
	//	/// </summary>
	//	protected virtual void ClearItems()
	//	{
	//		m_Core.Clear();
 //           OnDictionaryChanged(new DictionaryChangedEventArgs(NotifyDictionaryChangedAction.Reset));
    //		OnPropertyChanged(CommonProperties.CountProperty);
	//	}

	//	/// <summary>
	//	/// This is called whenever an item is replaced in the dictionary
	//	/// </summary>
	//	/// <param name="key"></param>
	//	/// <param name="newValue"></param>
	//	/// <param name="oldValue"></param>
	//	protected virtual void SetItem(TKey key, TValue oldValue, TValue newValue)
	//	{
	//		m_Core[key] = newValue;
 //           OnDictionaryChanged(new DictionaryChangedEventArgs(NotifyDictionaryChangedAction.Replace, key, oldValue, newValue));
	//	}

 //   }

}
